package ua.dou.rss;

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

import java.net.URL;

/**
 * Main connection point to the rss urls.
 * User: David Mayboroda
 */
public class RssReader {

    public SyndFeed parse(String connectionUrl) throws Exception{
        URL url = new URL(connectionUrl);
        XmlReader xmlReader = null;
        SyndFeed feed = null;
        try {
            xmlReader = new XmlReader(url);
            feed = new SyndFeedInput().build(xmlReader);
        } finally {
            if(xmlReader != null) { xmlReader.close(); }
        }
        return feed;
    }
}
